What is a "helper function?"Show Answer
A "helper function" is an extra function defined to solve some part of a
larger problem, often beyond what is required in the problem description
(although required functions can technically be helper functions too). For
example, in the rock-paper-scissors task, we required you to write a
function called randomGesture that returns a random gesture. To play
rock-paper-scissors, this function isn't necessary: we could just use the
code from it within our playComputer function directly. But by creating a
helper function for this purpose, our code becomes more modular and it's
easier to test many smaller components separately. Oftentimes, a helper
function can serve as a conceptual strategy in probelm solving: when things
are getting too complicated to think of a solution, you can imagine a
function that would help simplify the current problem, then write that
function as a helper function and come back to the larger problem once
you've solved the smaller one.
What is an "infinite loop" and how can you avoid creating one?Show Answer
An "infinite loop" is a loop that never ends, in most cases it is a while
loop where the loop condition never ends up being False. To avoid infinite
loops, makes sure that the code in your loop changes at least one variable
that's used in the loop condition, and that it does so in a way that will
eventually make that condition false. Also, if you know how many times you
want to execute the loop, use a for loop instead of a while loop.